﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;


/// <summary>
/// 响应事件分发
/// </summary>
class ResponseManager:Singleton<ResponseManager>
{
    /// <summary>
    /// 事件字典
    /// </summary>
    Dictionary<string, Action<GameData>> responseFuns = new Dictionary<string, Action<GameData>>();

    
    /// <summary>
    /// 添加响应事件
    /// </summary>
    /// <param name="FunctionName"></param>
    /// <param name="action"></param>
    public void AddResponseAction(string FunctionName,Action<GameData> action)
    {
        if (!responseFuns.ContainsKey(FunctionName))
        {
            responseFuns.Add(FunctionName, action);
        }
    }

    /// <summary>
    /// 事件分发器
    /// </summary>
    /// <param name="data"></param>
    public void EventDelivery(GameData data)
    {
        string funName = data.callFunction;
        
        if (responseFuns.ContainsKey(funName))
        {
            responseFuns[funName]?.Invoke(data);
        }

    }
}